
/**
 * 文件类型找到对应的字体icon
 */
var typeIcon = function(type, sname, pathType) {
	if(pathType==0 && type!=null){
		type = type.toLowerCase();
		if(type.indexOf('text')==0) {
			return 'fa fa-file-text-o';
		}else if(type.indexOf('image')==0) {
			return 'fa fa-file-image-o';
		}else if(type.indexOf('audio')==0) {
			return 'fa fa-file-audio-o';
		}else if(type.indexOf('video')==0) {
			return 'fa fa-file-video-o';
		}else if(type.indexOf('application')==0) {
			var i = type.indexOf('/');
			if(i>-1) {
				var subType = type.substr(i+1);
				if(subType.indexOf('zip')>-1 ) {
					return 'fa fa-file-zip-o';
				}else if( subType=='octet-stream' || subType.indexOf('msdownload')>-1) {
					if(sname!=null){
						var sname = suffixName(sname);
						if(sname=='rar' || sname=='exe' || sname=='jar' || sname=='war'){
							return 'fa fa-file-zip-o';
						}else if(sname=='apk'){
							return 'fa fa-android';
						}
					}
				}else if( subType.indexOf('itunes')>-1 || subType.indexOf('ipa')>-1 ) {
					return 'fa fa-apple';
				}else if( subType.indexOf('word')>-1 || subType.indexOf('document')>-1 ) {
					return 'fa fa-file-word-o';
				}else if( subType.indexOf('excel')>-1 || subType.indexOf('sheet')>-1 ) {
					return 'fa fa-file-excel-o';
				}else if( subType.indexOf('powerpoint')>-1 || subType.indexOf('presentation')>-1 ) {
					return 'fa fa-file-powerpoint-o';
				}else if( subType=='pdf' ) {
					return 'fa fa-file-pdf-o';
				}
			}
		}
	}else if(pathType==1){//http
		return 'fa fa-link';
	}else if(pathType==2){//电驴
		return 'fa fa-arrow-circle-o-down';
	}else if(pathType==3){//磁力
		return 'fa fa-magnet';
	}else if(pathType==4){//迅雷
		return 'fa fa-paper-plane-o';
	}
	return 'fa fa-file-o';
}

/**
 * 截取文件后缀名
 */
var suffixName = function(name){
	var i = name.lastIndexOf('.');
	return name.substr(i+1).toLowerCase();
}

/**
 * 文件大小单位
 */
var fileSize = function(bytes) {
	if (bytes === 0) return '0 B';
	var k = 1000, // or 1024
        sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
        i = Math.floor(Math.log(bytes) / Math.log(k));
	return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}

/**
 * 格式化时间
 */
var splitDate = function(time){
	if(time==null || time==''){
		return null
	}else {
		return time.split(' ')[0];
	}
}

/**
 * 文本转html
 */
var txt2html = function(txt) {
	return txt.replace(/(\r\n)|(\n)/g,'<br/>');
}